package com.lxk.finance.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.lxk.finance.domain.bo.AccUserAccountRecordBo;
import com.lxk.finance.domain.vo.AccUserAccountRecordVo;
import com.lxk.finance.service.IAccUserAccountRecordService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 账户流水
 *
 * @author LXK-RY5
 * @date 2024-07-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/finance/userAccountRecord")
public class AccUserAccountRecordController extends BaseController {

    private final IAccUserAccountRecordService accUserAccountRecordService;

    /**
     * 查询账户流水列表
     */
    @SaCheckPermission("finance:userAccountRecord:list")
    @GetMapping("/list")
    public TableDataInfo<AccUserAccountRecordVo> list(AccUserAccountRecordBo bo, PageQuery pageQuery) {
        return accUserAccountRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出账户流水列表
     */
    @SaCheckPermission("finance:userAccountRecord:export")
    @Log(title = "账户流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AccUserAccountRecordBo bo, HttpServletResponse response) {
        List<AccUserAccountRecordVo> list = accUserAccountRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "账户流水", AccUserAccountRecordVo.class, response);
    }

    /**
     * 获取账户流水详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("finance:userAccountRecord:query")
    @GetMapping("/{id}")
    public R<AccUserAccountRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(accUserAccountRecordService.queryById(id));
    }

    /**
     * 新增账户流水
     */
    @SaCheckPermission("finance:userAccountRecord:add")
    @Log(title = "账户流水", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AccUserAccountRecordBo bo) {
        return toAjax(accUserAccountRecordService.insertByBo(bo));
    }

    /**
     * 修改账户流水
     */
    @SaCheckPermission("finance:userAccountRecord:edit")
    @Log(title = "账户流水", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AccUserAccountRecordBo bo) {
        return toAjax(accUserAccountRecordService.updateByBo(bo));
    }

    /**
     * 删除账户流水
     *
     * @param ids 主键串
     */
    @SaCheckPermission("finance:userAccountRecord:remove")
    @Log(title = "账户流水", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(accUserAccountRecordService.deleteWithValidByIds(List.of(ids), true));
    }
}
